package com.bayss.core.util;

import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by LDL on 2019/12/29.
 */
public class SkuUtil {
    /**
     * sku_time_code_code_code
     */
    public static List<String> parseSpuCode(String codes) {
        if (StringUtils.isEmpty(codes) || !codes.startsWith("spu_")) {
            return new ArrayList<>();
        }
        String spuCodeStr = codes.split("spu_")[1];
        return Arrays.asList(spuCodeStr.split("_"));
    }

    public static String formatSpuCode(String code) {
        return "spu_" + System.currentTimeMillis() + "_" + code;
    }

    public static String getSpuCodeFirst(String code) {
        String[] item = code.split("_");
        return item[0] + "_" + item[1] + "_";
    }
}
